﻿
namespace anael.Data.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using anael.Data.Model;
    
    
    // Implements application logic using the ModelContainer context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DomainService : LinqToEntitiesDomainService<ModelContainer>
    {
        
        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'CategorieSet' query.
        public IQueryable<Categorie> GetCategorieSet()
        {
            return this.ObjectContext.CategorieSet;
        }
        
        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'PersonneSet' query.
        public IQueryable<Personne> GetPersonneSet()
        {
            return this.ObjectContext.PersonneSet;
        }
        
        public void InsertPersonne(Personne personne)
        {
            if ((personne.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(personne, EntityState.Added);
            }
            else
            {
                this.ObjectContext.PersonneSet.AddObject(personne);
            }
        }
        
        public void UpdatePersonne(Personne currentPersonne)
        {
            this.ObjectContext.PersonneSet.AttachAsModified(currentPersonne, this.ChangeSet.GetOriginal(currentPersonne));
        }
        
        public void DeletePersonne(Personne personne)
        {
            if ((personne.EntityState == EntityState.Detached))
            {
                this.ObjectContext.PersonneSet.Attach(personne);
            }
            this.ObjectContext.PersonneSet.DeleteObject(personne);
        }
    }
}


